import { doGetAdminInfos, doGetAdminInfo, doGetAdminInfo1, doGetAdminInfo2, doGetAdminInfo3, doGetAdminInfo4 } from '@/api/admin'

const state = {
  info: {}
}

const mutations = {
  // TOGGLE_INFO: (state, info) => {
  //   for (var k in info) {
  //     if (object.hasOwnProperty(k)) {
  //       state.info[k] = info[k]
  //     }
  //   }
  // },
}

const actions = {
  getAdminInfos({ commit, state }) {
    return new Promise((resolve, reject) => {
      doGetAdminInfos().then(response => {
        console.log("@/store/admin/index.js getAdminInfos()", response)
        const { data } = response
        //commit('TOGGLE_INFO', data)
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  getAdminInfo({ commit, state }, id) {
    return new Promise((resolve, reject) => {
      doGetAdminInfo(id).then(response => {
        console.log("@/store/admin/index.js getAdminInfo()", response)
        const { data } = response
        // commit('TOGGLE_INFO', data)
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  getAdminInfo1({ commit, state }, id) {
    return new Promise((resolve, reject) => {
      doGetAdminInfo1(id).then(response => {
        console.log("@/store/admin/index.js getAdminInfo1()", response)
        const { data } = response
        // commit('TOGGLE_INFO', data)
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  getAdminInfo2({ commit, state }, obj) {
    return new Promise((resolve, reject) => {
      doGetAdminInfo2(obj).then(response => {
        console.log("@/store/admin/index.js getAdminInfo2()", response)
        const { data } = response
        // commit('TOGGLE_INFO', data)
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  getAdminInfo3({ commit, state }, id) {
    return new Promise((resolve, reject) => {
      doGetAdminInfo3(id).then(response => {
        console.log("@/store/admin/index.js getAdminInfo3()", response)
        const { data } = response
        // commit('TOGGLE_INFO', data)
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  getAdminInfo4({ commit, state }, obj) {
    return new Promise((resolve, reject) => {
      doGetAdminInfo4(obj).then(response => {
        console.log("@/store/admin/index.js getAdminInfo4()", response)
        const { data } = response
        // commit('TOGGLE_INFO', data)
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
